package org.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

/*This class is called when the user wishes to make call or email to the seller he sees
 * on ths book details
 * */
public class MakeCallSendEmailActivity extends Activity {
	private TextView student;
	String email, phone, Student;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.makecallsendemaillayout);

		student = (TextView) findViewById(R.id.student);

		Bundle extras = getIntent().getExtras();

		if (extras == null) {
			return;
		}
		email = (String) extras.getSerializable("email");
		phone = (String) extras.getSerializable("phone");
		Student = (String) extras.getSerializable("Student");

		System.out.println("Email: " + email);
		System.out.println("phone: " + phone);
		System.out.println("Student: " + Student);

		student.setText(Student);
	}
	
	//The onclick method called when the user selecs the "Call" button from the UI
	public void Call(View v) throws Exception {

		String phno = "tel:" + phone;

		Intent i = new Intent(Intent.ACTION_DIAL, Uri.parse(phno));
		startActivity(i);
	}
	//The onclick method called when the user wishes to email the seller
	public void Email(View v) throws Exception {

		Intent i = new Intent(Intent.ACTION_SEND);
		i.setType("text/plain");
		i
				.putExtra(Intent.EXTRA_EMAIL,
						new String[] { "recipient@example.com" });
		i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
		i.putExtra(Intent.EXTRA_TEXT, "body of email");
		try {
			startActivity(Intent.createChooser(i, "Send mail..."));
		} catch (android.content.ActivityNotFoundException ex) {
			Toast
					.makeText(MakeCallSendEmailActivity.this,
							"There are no email clients installed.",
							Toast.LENGTH_SHORT).show();
		}

	}

}